package ru.hh.team02.chat.messaging;

import java.util.Set;

import ru.hh.team02.chat.client.Client;
import ru.hh.team02.chat.server.ChatServer;

/**
 * class responsible for macro sending logic. current version - one queue with
 * messages per active client
 */
public class SendingService {

    /**
     * Put the message for sending in the queue. The addressee is already
     * encapsulated inside the message.
     * 
     * @param message
     */
    // public static void sendMessage(Message message) {
    // sendingQueue.add(message);
    // }

    /**
     * Put message to all personal queues of people, who are in the same room as
     * sender
     * 
     * @param text
     *            Message text
     * @param name
     *            Sender name
     */
    public void sendMessageToRoom(String text, String senderName) {
        String room = ChatServer.registry.getClientRoom(senderName);
        Set<Client> recepients = ChatServer.registry.getClientsFromRoom(room);

        for (Client recepient : recepients) {
            Message message = new Message(text);
            recepient.add(message);
        }

    }
}
